<template>
  <div v-if="hotCity">
    <!-- 热门城市 -->
    <div class="hot">
      <header class="title">热门城市</header>
      <div
        class="hot-city"
        v-for="value in hotCity.cities"
        :key="value.cityId"
        @click="toHome(value)"
      >
        {{ value.name }}
      </div>
    </div>

    <!-- 其他城市 -->
    <div class="item" v-for="item in otherCity" :key="item.prefix">
      <header class="title">{{ item.prefix.toUpperCase() }}</header>
      <div
        class="city"
        v-for="value in item.cities"
        :key="value.cityId"
        @click="toHome(value)"
      >
        {{ value.name }}
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapActions, mapGetters } from "vuex";
export default {
  mounted() {
    this.getCityListAsync();
  },
  computed: mapGetters("city", ["hotCity", "otherCity"]),
  methods: {
    ...mapMutations("city", ["changeCity"]),
    ...mapActions("city", ["getCityListAsync"]),
    toHome(city) {
      this.changeCity(city);
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="less" scoped>
.title {
  background-color: #ebebeb;
  font-size: 16px;
  line-height: 24px;
  color: #333;
  height: 24px;
  width: 100%;
  padding-left: 20px;
}
.city {
  height: 0.88rem;
  line-height: 0.88rem;
  margin-left: 0.3rem;
  border-bottom: 0.02rem solid #c8c7cc;
}

.hot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
  .hot-city {
    width: 30%;
    border: 1px solid #333;
    margin-top: 20px;
    overflow: hidden;
  }
}

// .item:first-child {
//   display: flex;
//   flex-wrap: wrap;
//   justify-content: space-evenly;
//   .city {
//     width: 30%;
//     border: 1px solid #333;
//     margin-top: 20px;
//     overflow: hidden;
//   }
// }
</style>
